<?php
include_once "../include/config.php";
include_once "../include/db.php";
include_once "../functions.php";
include_once "../snippets.php";
include_once "../user.php";

// connect to db
mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());

// get task
if(isset($_GET['task'])) { $task = $_GET['task']; } 
else if(isset($_POST['task'])) { $task = $_POST['task']; }

// get view
if(isset($_GET['view'])) { $view = $_GET['view']; } 
else if(isset($_POST['view'])) { $view = $_POST['view']; }
else { $view = ""; }

// get page
if(isset($_GET['p'])) { $p = $_GET['p']; } 
else if(isset($_POST['p'])) { $p = $_POST['p']; }
else { $p = 1; }

// get search
if(isset($_GET['search'])) { $search = $_GET['search']; } 
else if(isset($_POST['search'])) { $search = $_POST['search']; }
else { $search = ""; }


$id_user = User::id();

if(!User::isAdmin()) {
  $filterUserId =  " AND id_user='$id_user'";
}
// get marker totals
$total_approved = mysql_num_rows(mysql_query("SELECT id FROM places WHERE approved='1'".$filterUserId));
$total_rejected = mysql_num_rows(mysql_query("SELECT id FROM places WHERE approved='0'".$filterUserId));
$total_pending = mysql_num_rows(mysql_query("SELECT id FROM places WHERE approved='2'".$filterUserId));
$total_all = mysql_num_rows(mysql_query("SELECT id FROM places WHERE 1".$filterUserId));

// admin header
$admin_head = "<!DOCTYPE html>
  <html>
  <head>
    <title>La web de las protestas</title>
    <meta name='viewport' content='width=device-width, initial-scale=1.0, user-scalable=no'>
    <meta http-equiv='content-type' content='text/html; charset=UTF-8' />
    <link href='../bootstrap/css/bootstrap.css' rel='stylesheet' type='text/css' />
    <link href='../bootstrap/css/bootstrap-responsive.css' rel='stylesheet' type='text/css' />
    <link href='admin.css' rel='stylesheet' type='text/css' />
    <script src='../scripts/jquery-1.9.1.min.js' type='text/javascript' charset='utf-8'></script>
    <script src='../bootstrap/js/bootstrap.js' type='text/javascript' charset='utf-8'></script>
    
    ".renderGoogleAnalytics()."
    
  </head>
  <body>
";

$admin_head .= "
    <div class='navbar navbar-fixed-top'>
      <div class='navbar-inner'>
        <div class='container'>
          <a class='brand' href='index.php'>
            Administración de Protestas
          </a>
          <ul class='nav'>
            <li".(($view == "")?" class='active'":"").">
              <a href='index.php'>Todas</a>
            </li>
            <li".(($view == "approved")?" class='active'":"").">
              <a href='index.php?view=approved'>
                Aprobadas
                <span class='badge badge-info'>$total_approved</span>
              </a>
            </li>
            <li".(($view == "pending")?" class='active'":"").">
              <a href='index.php?view=pending'>
                Pendientes
                <span class='badge badge-info'>$total_pending</span>
              </a>
            </li>
            <li".(($view == "rejected")?" class='active'":"").">
              <a href='index.php?view=rejected'>
                Rechazadas
                <span class='badge badge-info'>$total_rejected</span>
              </a>
            </li>
          </ul>
          <form class='navbar-search pull-left' action='index.php' method='get'>
            <input type='text' name='search' class='search-query' placeholder='Search' autocomplete='off' value='$search'>
          </form>
          <ul class='nav pull-right'>
            <li><a href='../index.php'>Volver".(($view == "rejected")?" ":"")."</a></li>
          </ul>
        </div>
      </div>
    </div>
  <div class='container-fluid' id='content'>
";



// admin footer 
$admin_foot = "
    </div>
  </body>
</html>
";




?>